package com.example.pc.day_10_8;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;

import java.io.Serializable;

/**第一步:定义一个广播接收者*/
public class MyReceiver extends BroadcastReceiver{

    private String TAG =MyReceiver.class.getSimpleName();

    /**用于接收广播消息*/
    @Override
    public void onReceive(Context context, Intent intent) {

        String action = intent.getAction();
        if (action != null){
            switch (action) {
                case "a.b.c.d":
                    Toast.makeText(context, "1111111111", Toast.LENGTH_SHORT).show();
                    break;
                case "a.b.c.d1":
                    Toast.makeText(context, "222222222", Toast.LENGTH_SHORT).show();
                    break;
                case "a.b.c.d2":

                    break;
                case "a.b.c.d3":
                    break;
                case "a.b.c.d4":
                    break;

            }
        }

        int i = intent.getIntExtra("i", -1);
        String s = intent.getStringExtra("s");

        Log.d(TAG, "MyReceiver  onReceive: 收到广播消息s:" + s + ",i=" + i);
        Toast.makeText(context, "fhjdhkdh", Toast.LENGTH_SHORT).show();

//        abortBroadcast();//放弃广播(使得后面的广播接收者接收不到该广播消息)

        setResultData("这是MyReceiver的数据.给下一个接收者");
//        setResultCode();
//        setResultExtras();
//        setResult();
    }
}
